package com.kyh.controller.api.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kyh.service.sys.ButtonService;
import com.kyh.sys.entity.Button;
import com.kyh.vo.BootstrapTableVoJA;
import com.kyh.vo.R;

@Controller
@RequestMapping("/api/inter/button")
public class ApiInterButtonController {

	@Autowired
	private ButtonService buttonService;
	
	@RequestMapping("/search")
    @ResponseBody
	public BootstrapTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute Button cond,
			Long roleId
			){
		
		if (roleId != null) {
			cond.where("A.button_id in (select button_id from sys_role_button where role_id = " + roleId + " and status = 1)");
		}
		
		return buttonService.search(cond);
	}
	
	@RequestMapping("/tree")
    @ResponseBody
	public R tree(Model model, HttpServletRequest request, HttpServletResponse response
			){
		
		return buttonService.tree();
	}
}